<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ include file="/commons/taglibs.jsp" %>
<%@ include file="/commons/commonjs.jsp" %>
<%@ include file="/commons/grid.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>文档列表</title>
<link rel="shortcut icon" href="/Include/favicon.ico" type="image/x-icon" />
<link href="/Include/Default.css" rel="stylesheet" type="text/css">

<!-- 列表js -->
<script type="text/javascript" src="${ctx}/js/sys/role/role_grid.js" ></script>
<script type="text/javascript" >
//////////////////////////////////////////////////////////
//测试查询
function query() {
	var param={
		name : Sigma.Util.getValue(Sigma.$('q_menuNames'))
	}
	alert( "在查询数据的request中, 将会有如下参数:\n\n"+Sigma.toQueryString(param) );
	alert(mygrid.query);
	mygrid.query(param);
}
 
 //测试过滤
function doFilter(){
   alert(Sigma.Util.getValue(Sigma.$('q_menuName')));
   var filterInfo=[
	   {
	      fieldName : "menuName",
	      logic : "startWith",
	      value : Sigma.Util.getValue(Sigma.$('q_menuName'))
	   }
   ]
   var grid=Sigma.$grid("myGrid1");
   //var rowNOs = grid.applyFilter(filterInfo);
   //var grid = Sigma.$grid("myGrid1");
   //alert(grid);
   var rowNOs = grid.filterGrid(filterInfo); 
}
 
 function doUnfilter(){
    var grid = Sigma.$grid("myGrid1");
    var rowNOs=grid.applyFilter([]);
 
}


function goUpdate(){
	var diag = new Dialog();
	diag.Modal = false;
	diag.Left = 600;
	diag.Title = "弹出没有遮罩层的窗口";
	diag.URL = "/sys/role/form";
	diag.show();
}
	
function showEditDialog()
{
//  /sys/role/{id}/edit
	var url;
	var gsr = mygrid.getSelectedRecords();
	var length = gsr.length;
   	if(length==1){
   		var id = gsr[0].id;
   		url = "/sys/role/"+id+"/edit";
   		var diag = new Dialog();
   		//diag.Modal = false; //可以点击弹出框的菜单，这样会引起弹出框无法操作的问题。
		diag.Width = 500;
		diag.Height = 400;
		diag.Title = "修改菜单";
		diag.URL = url;
		diag.show();
	}else{
		Dialog.alert('只能选择其中一条记录进行操作');
	}
	
}

 function showAddDialog(){
	
	var diag = new Dialog();
	diag.Width = 500;
	diag.Height = 400;
	diag.Title = "添加菜单";
	diag.URL = "/sys/role/create";
	diag.show();
	 
 }
 
 //做到只是获取id值
 function selectRecords(rows){
 		var gsr = mygrid.getSelectedRecords();
 		var length = gsr.length;
     	if(length<=0){
 			Dialog.alert('至少选择一条记录进行操作');
 		}else{
	 		var ids = [];
	 		for(var row_id = 0;row_id<length;row_id++){
	 			ids.push(gsr[row_id].id);
	 			//alert(gsr[row_id].icon);//都是以这种方式获取
	 		}
	     	ids.join(',');
			Dialog.confirm('警告：您确认要进行删除吗？',function(){
				$.ajax({ 
					type: "DELETE",        // PUT(index) post(save)
					url : "/sys/role",  ///sys/role/1629 这样可以进行单个删除，要进行批量删除 //"/sys/role?items="+ids
					data:  ""+ids+"",  //传递数据 //通过这可以传递
					cache : false,
					dataType: "json", //接受数据格式,注意数据接受格式：html、json、xml等,哦原来是这里的原因，我晕 --- json 不行   
					error : function(json) {
						alert("error");
						//alert(json.error);
					},
					success: function(json){
						//alert(json.error);
						if(json.success=='删除成功'){
							Dialog.alert('删除成功',function(){
								mygrid.reload();
							},150,50);	
						}else if(json.error=='删除失败'){
							Dialog.alert('删除失败',function(){
								mygrid.reload();
							},150,50);
						}
					}
				});
			});
     	}	
	}
</script>


</head>
<body style="padding:0px;margin:6px;">
					菜单:
					<input type="text" name="name" value="liang" id="q_menuName">
					
				<DIV style="margin:5px;">
					<input type='button' class='button' name='addBtn' id='addBtn'value='新   增'
 onclick='showAddDialog()' />
 &nbsp;&nbsp;
					<input type='button' class='button' name='addBtn' id='addBtn'value='修   改'
 onclick='showEditDialog()' />&nbsp;&nbsp;
 		<!-- Sigma.$json(mygrid.getSelectedRecords() ) -->
			<input type='button' class='button' name='addBtn' id='addBtn' value='删  除'
 onclick='selectRecords()' />
 			</DIV>
 			<%--
			<input type="button" value="删除" id="btn1" onclick="selectRecords();" />&nbsp;&nbsp;&nbsp;
			<a id="delete" href="#" onmousedown="selectRecords()" class="thickbox">删除</a>
			 --%>
			</div>
		</form>
	<div id="mygrid_container" 
		style="border:0px solid #cccccc;background-color:#f3f3f3;margin-left:10px;padding-left:15px;width:95%;">
		
		
	</div>
	
</body>
</html>